package com.wang.builder;

import java.util.Date;

public class BuilderEntity {

    public static void main(String[] args) {
        BuilderEntity entity = new Builder()
                .name("wang").age(25).builder();
        System.out.println(entity.toString());
        BuilderEntity entity1 = new Builder()
                .name("yang").age(29).builder();
        System.out.println(entity1.toString());
    }

    private final String name;
    private final String summary;
    private final String context;
    private final int age;
    private final Date birthday;


    private BuilderEntity(Builder builder){
        this.name = builder.name;
        this.summary = builder.summary;
        this.context = builder.context;
        this.age = builder.age;
        this.birthday = builder.birthday;
    }

    public static class Builder{

        private String name;
        private String summary;
        private int age;
        private String context;
        private Date birthday;

        public Builder name(String name){
            this.name = name;
            return this;
        }

        public Builder summary(String summary){
            this.summary = summary;
            return this;
        }

        public Builder age(int age){
            this.age = age;
            return this;
        }

        public Builder context(String context){
            this.context = context;
            return this;
        }

        public Builder birthday(Date birthday){
            this.birthday = birthday;
            return this;
        }

        public BuilderEntity builder(){
            return new BuilderEntity(this);
        }
    }

    @Override
    public String toString() {
        return "BuilderEntity{" +
                "name='" + name + '\'' +
                ", summary='" + summary + '\'' +
                ", context='" + context + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                '}';
    }
}
